<%@ page import="com.hqyj.education.entity.User" %><%--
  Created by IntelliJ IDEA.
  User: 高万檬
  Date: 2020/8/7
  Time: 8:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    /*basePath===http://localhost:8080/TestServlet04/*/
//     User user= (User) request.getSession().getAttribute("u");
//     int userRoleId=user.getUserRole();
%>
<html>
<head>
    <title>教师个人信息管理</title>
    <link rel="stylesheet" href="<%=basePath%>static/css/pintuer.css">
    <link rel="stylesheet" href="<%=basePath%>static/css/admin.css">
    <link rel="stylesheet" href="<%=basePath%>static/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="<%=basePath%>static/css/bootstrap.min.css">
    <script type="text/javascript" src="<%=basePath%>static/js/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="<%=basePath%>static/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="<%=basePath%>static/js/jqPaginator.js"></script>
</head>
<body>
<div id="window"
     style="position: absolute;left: 30%;top:20%;width: 400px;height: 400px;background-color: #a6e1ec;display: none;">
    <center>
        <input type="hidden" name="id" id="id">
        <span>教师id:</span><input type="text" name="tid" id="tid" readonly="true"><br>
        <span>教师编号:</span><input type="text" name="tno" id="tno" readonly="true"><br>
        <span>教师姓名:</span><input type="text" name="tname" id="tname" readonly="true"><br>
        <span>密码:</span><input type="text" name="tpwd" id="tpwd"><br>
        <span>年龄:</span><input type="text" name="age" id="age" readonly="true"><br>

        <span>地址:</span> <input type="text" name="address" id="address" readonly="true"><br>
        <span>性别:</span> <input type="text" name="sex" id="sex" readonly="true"><br>
        <span>sc_check_id:</span><input type="text" name="tc_CheckId" id="tc_CheckId" readonly="true"><br>
        <%--        <span>sdmm_id：</span>   <input type="text" name="sdmmId" id="sdmmId" readonly = "true"><br>--%>
        <%--        <span>sc_class_id：</span><input type="text" name="scClassId" id="scClassId" readonly = "true"><br>--%>
        <%--        <span>isordelete：</span><input type="text" name="isordelete" id="isordelete" readonly = "true"><br>--%>
        <%--        <span>student_role：</span><input type="text" name="studentRole" id="studentRole" readonly = "true"><br>--%>
        <input type="button" value="修改" onclick="updateTeacherPwdById()">
        <input type="reset" value="取消" onclick="closeWindow()">
    </center>
</div>
<table class="table table-hover" border="1" width="50%">
    <tr>
        <td>教师id</td>
        <td>教师编号</td>
        <td>教师姓名</td>
        <td>教师密码</td>
        <td>性别</td>
        <td>地址</td>
        <td>年龄</td>
        <td>sc_check_id</td>
        <%--        <td>sdmm_id</td>--%>
        <%--        <td>sc_class_id</td>--%>
        <%--        <td>isordelete</td>--%>
        <%--        <td>student_role</td>--%>
        <td colspan="2">操作</td>

    </tr>
    <tbody id="tb">
    </tbody>
</table>
<script>
    $(document).ready(function () {
        loadData();
    });

    function loadData() {
//jquery的ajax请求方法

        var roleId= <%=session.getAttribute("userRoleId")%>;
        var tid= <%=session.getAttribute("userId")%>;
        console.log(roleId);
        $.ajax({
            url: "<%=basePath%>teacher/queryteacherinfo",
            async: false,//同步请求（默认）
            type: "POST",
            dataType: "json",
            data: {"tid":tid,"roleid":roleId},
            success: function (data) {
                console.log(data);
//使用jquery形式遍历
// $.each(data.list, function (n, val) {
                    $("#tb").html("");
                    if(data.length>0){
                        //使用jquery形式遍历
                        $.each(data,function(n,val){
                            var html = "";
                            html += "<tr>" +
                                "<td>" + val.tid+ "</td>" +
                                "<td>" + val.tno+ "</td>" +
                                "<td>" + val.tname + "</td>" +
                                "<td>" + val.tpwd+ "</td>" +
                                "<td>" + val.sex+ "</td>" +
                                "<td>" + val.address + "</td>" +
                                "<td>" + val.age+ "</td>" +
                                "<td>" + " "+ "</td>" +
                                "<td>" +
                                "<button class=\"button border-main icon-plus-square-o\"  type='button' onclick='updateWindow(this)'>修改</button>" +
                                // "<button class=\"button border-main icon-plus-square-o\"  type='button' onclick='delWindow("+val.s_id+")'>删除</button>" +
                                "</td>" +
                                "</tr>";
                            $("#tb").append(html);
                        });
                    }else{
                        $("#tb").append("<tr><td colspan=8 align=\"center\">暂时没有数据哦，快去添加一条吧</td></tr>");
                    }
                },
                error:function(){
                    alert("服务器出错！");
                }
            });

    }

    //打开修改的模态框
    function updateWindow(obj) {
//显示修改的模态框
        $("#window").show();
//获取当前选中行的所有数据
        var tid = $(obj).parent().parent().find("td").eq(0).text()
        var tno = $(obj).parent().parent().find("td").eq(1).text()
        var tname = $(obj).parent().parent().find("td").eq(2).text()
        var tpwd = $(obj).parent().parent().find("td").eq(3).text()
        var address = $(obj).parent().parent().find("td").eq(5).text()
        var sex= $(obj).parent().parent().find("td").eq(6).text()
        var scCheckId = $(obj).parent().parent().find("td").eq(7).text()
        // var sdmmId = $(obj).parent().parent().find("td").eq(8).text()
        // var scClassId = $(obj).parent().parent().find("td").eq(9).text()
        // var isordelete = $(obj).parent().parent().find("td").eq(10).text()
        // var studentRole = $(obj).parent().parent().find("td").eq(11).text()

        console.log("locked=" + id)
//把选中行的数据复制给修改框里的表单元素
        $("#tid").val(tid);
        $("#tno").val(tno);
        $("#tname").val(tname);
        $("#tpwd").val(tpwd);
        // $("#entrancetime").val(entrancetime);
        $("#sex").val(sex);
        $("#address").val(address);
        $("#scCheckId").val(scCheckId);
        // $("#sdmmId").val(sdmmId);
        // $("#scClassId").val(scClassId);
        // $("#isordelete").val(isordelete);
        // $("#studentRole").val(studentRole);

    }

    //修改操作
    function updateTeacherPwdById() {


//获取文本框的值

        var tid = $("#tid ").val();

        console.log("这是tid"+tid)
        var tno = $("#tno ").val();
        var tname = $("#tname ").val();
        var tpwd = $("#tpwd").val();
        // var entrancetime = $("#entrancetime").val();
        var age = $("#age").val();
        var sex = $("#sex").val();
        var address = $("#address").val();
        // var scCheckId = $("#scCheckId").val();
        // var sdmmId = $("#sdmmId").val();
        // var scClassId = $("#scClassId").val();
        // var isordelete = $("#isordelete").val();
        // var studentRole = $("#studentRole").val();


        $.ajax({
            url: "<%=basePath%>teacher/updateteacher",
            type: "Post",
            data: {
                "tno":tno,
                "tpwd": tpwd,
            },
            dataType: "json",//传json
            success: function (data) {
                console.log(data)
                alert("修改成功")
//关闭模态框
                $("#window").hide();
//刷新
// loadData();
                window.location.reload();
            }
        })

    }

    function closeWindow() {
        $("#window").hide();
    }
</script>
</body>
</html>
